<?php

use Illuminate\Database\Seeder;

class PostTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker = Faker\Factory::create();
        $category_ids = \App\Models\Category::pluck('id')->toArray();
        $datas = [];
        foreach (range(1, 15) as $key => $value) {
            $datas[] = [
                'category_id' => $faker->randomElement($category_ids),
                'title' =>  $faker->word ,
                'slug' =>  $faker->unique()->word ,
                'summary' =>  $faker->word ,
                'thumb' =>  $faker->url ,
                'content' =>  $faker->text ,
                'comment_count' =>  $faker->randomNumber() ,
                'view_count' =>  $faker->randomNumber() ,
                'favorite_count' =>  $faker->randomNumber() ,
                'published' =>  $faker->numberBetween(0,1) ,
                'published_at' =>  $faker->dateTimeBetween('-1 years') ,
                'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
                'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
            ];
        }
        DB::table('posts')->insert($datas);
    }
}
